home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
prodpack.zip
/
DB4PPSRC.EXE
/
SCR2DBF.COD
< prev
next >
Wrap
Text File
|
1993-05-23
|
11KB
|
363 lines
$Header: /cms/ports.v/src/dbb/scr2dbf.cod,v 1.0 07 Apr 1993 17:44:44 chofmann $
NAME
SCR2DBF.COD - Creates a DBF file based in the contents of a given SCR
DESCRIPTION
Scr2Dbf will take a SNL file made from a SCR file and create a program
that makes a DBF file. This intended to hook in to the OACC for
building dialog boxes, or even screens for that matter.
The long character fields, those that accept 80 or more characters,
will be stored as MEMO fields. The memo block size will be reduced to
64 for compression purposes.
Scr2Dbf will place TEXT strings into the TEMPLATE holder, designate
the field is a calc field of type (FLD_VALUE_TYPE) "T".
For boxes, instead of extending the structure to handle the extra box
attributes, Scr2Dbf will store the box in a calc field of type
(FLD_VALUE_TYPE) "B", and place the other attributes into the
following places:
BOX_TYPE -> FLD_MEM_TYP, BOX_SPECIAL_CHAR -> FLD_FILENAME,
BOX_LEFT -> ROW_POSITN, BOX_TOP -> COL_POSITN, BOX_WIDTH -> FLD_LENGTH,
BOX_HEIGHT -> FLD_DECIMALS.
Scr2Dbf will ignore the SCR header information, such as FRAME_PATH,
or FRAME_MUN_OF_FIELDS, once it has determined that is processing
a form object.
Scr2Dbf will store values in order of occurance, from top left to
bottom right.
The generated program will always be called Scr2Dbf for now. The
DBF file it creates will also be called Scr2Dbf. This is to avoid
conflicts where the form name is the same as an existing DBF file.
ASSUMPTIONS
SFX_LIB, which contains routines like _MakeExte(), is loaded as SYSPROC.
{
include "form.def" // Form selectors
include "builtin.def" // Builtin functions
if getenv("dtl_debug") then
debug(2)
breakpoint( pick_debug )
endif
//
// Enum string constants for international translation
//
enum TRUE = 1,
FALSE = 0,
offset = 2, // Offset for lmarg()
range_require = 2, // Bit for range required set
valid_required = 4, // " " edit " "
screen_width = 80, // Screen width for now
err_ext = ".err"
;
var bnl_formname, // Name of BNL file to newframe if argument() has value
create_error, // Indicates if there were problems creating programs
arg_list;
arg_list = argument()
if arg_list != "" then
bnl_formname = token( ",", arg_list, 1 )
if !newframe( bnl_formname ) then
return -1;
endif
endif
if FRAME_CLASS != form then // We are not processing a form object
pause(wrong_class + any_key)
goto NoGen;
endif
if not create( "scr2dbf.prg" ) then
pause( "Could not create file: SCR2DBF.PRG" )
return 0;
endif
write_prg_header();
//-- Scan all the elements
foreach ELEMENT k
case ELEMENT_TYPE of
@TEXT_ELEMENT:
}
APPEND BLANK
REPLACE template WITH {delimit_string( TEXT_ITEM )}
REPLACE fieldtype WITH "5"
REPLACE value_type WITH "T"
REPLACE row WITH {nul2zero( ROW_POSITN ) }
REPLACE col WITH {nul2zero( COL_POSITN ) }
REPLACE sys_flen WITH {nul2zero( SYS_FLEN ) }
REPLACE display WITH {nul2zero( FLD_DISPLAY ) }
{
@BOX_ELEMENT:
}
APPEND BLANK
REPLACE descript WITH 'BOX'
REPLACE fieldtype WITH "6"
REPLACE value_type WITH "B"
REPLACE mem_typ WITH {nul2zero( BOX_TYPE ) }
REPLACE filename WITH {delimit_string( BOX_SPECIAL_CHAR )}
REPLACE row WITH {nul2zero( BOX_TOP ) }
REPLACE col WITH {nul2zero( BOX_LEFT ) }
REPLACE length WITH {nul2zero( BOX_WIDTH ) }
REPLACE decimals WITH {nul2zero( BOX_HEIGHT ) }
REPLACE display WITH {nul2zero( FLD_DISPLAY ) }
{
@FLD_ELEMENT:
}
APPEND BLANK
REPLACE fieldname WITH '{FLD_FIELDNAME}'
REPLACE fieldtype WITH '{nul2zero( FLD_FIELDTYPE ) }'
REPLACE value_type WITH '{chr( FLD_VALUE_TYPE )}'
REPLACE filename WITH '{FLD_FILENAME}'
REPLACE row WITH {nul2zero( ROW_POSITN ) }
REPLACE col WITH {nul2zero( COL_POSITN ) }
REPLACE sys_flen WITH {nul2zero( SYS_FLEN ) }
REPLACE length WITH {nul2zero( FLD_LENGTH ) }
REPLACE decimals WITH {nul2zero( FLD_DECIMALS ) }
REPLACE template WITH {delimit_string( FLD_TEMPLATE )}
REPLACE picfun WITH {delimit_string( FLD_PICFUN )}
REPLACE pic_choice WITH {delimit_string( FLD_PIC_CHOICE )}
REPLACE pic_scroll WITH {nul2zero( FLD_PIC_SCROLL ) }
REPLACE descript WITH {delimit_string( FLD_DESCRIPT )}
REPLACE expression WITH {delimit_string( FLD_EXPRESSION )}
REPLACE l_bound WITH {delimit_string( FLD_L_BOUND )}
REPLACE u_bound WITH {delimit_string( FLD_U_BOUND )}
REPLACE def_val WITH {delimit_string( FLD_DEF_VAL )}
REPLACE ed_cond WITH {delimit_string( FLD_ED_COND )}
REPLACE ok_cond WITH {delimit_string( FLD_OK_COND )}
REPLACE rej_msg WITH {delimit_string( FLD_REJ_MSG )}
REPLACE hlp_msg WITH {delimit_string( FLD_HLP_MSG )}
REPLACE mem_typ WITH {nul2zero( FLD_MEM_TYP ) }
REPLACE editable WITH {nul2zero( FLD_EDITABLE ) }
REPLACE carry WITH {( FLD_CARRY > 0 ? ".T." : ".F." )}
REPLACE display WITH {nul2zero( FLD_DISPLAY ) }
REPLACE style WITH {nul2zero( FLD_STYLE ) }
{
endcase
next k;
}
INDEX ON RECNO() FOR fieldtype = "5" TAG Text
INDEX ON RECNO() FOR fieldtype = "6" TAG Box
INDEX ON STR(groupid,4) + STR(currentid,4) TAG ObjOrder
INDEX ON fieldname FOR .NOT. fieldtype $ "56" TAG Field
RETURN
*-- EOP: FillDbf
{
NoGen:
return 0;
//-- end: scr2dbf
//---------------------------------------
// Template user defined functions follow
//---------------------------------------
define write_prg_header()
//-------------------------------------------------------------------
// NAME
// write_prg_header - creates the program header for Scr2Dbg.prg
//-------------------------------------------------------------------
}
PROCEDURE Scr2Dbf
PARAMETERS pc_DbfName
*----------------------------------------------------------------------------
* NAME
* Scr2Dbf - Creates a DBF based on an SCR file.
*
* DESCRIPTION
*
* PARAMETERS
* pc_DbfName = Name of the DBF to create.
*
*----------------------------------------------------------------------------
IF SET( "TALK" ) = "ON"
SET TALK OFF
ll_talk = .t.
ELSE
ll_talk = .f.
ENDIF
lc_tmp = _TmpName( ".DBF" )
DO WHILE UPPER( lc_tmp ) = UPPER( pc_DbfName )
lc_tmp = _TmpName( ".DBF" )
ENDDO
IF _MakeExte( lc_tmp )
DO MakeStru
DO FillDbf
ELSE
DO _Err_Box WITH "Could not create the tmp structure file"
ENDIF
IF ll_talk
SET TALK ON
ENDIF
RETURN
*-- EOP: Scr2Dbf WITH pc_DbfName
PROCEDURE MakeStru
*----------------------------------------------------------------------------
* NAME
* MakeStru - Make the DBF structure for creating the fill DBF file
*
* VARIABLES
* lc_tmp = name of the tmp DBF file for the structure
* pc_DbfName = name of the actual DBF file to create based on structure
*----------------------------------------------------------------------------
USE ( lc_tmp )
DO AppendFld WITH "FIELDNAME", "C", 10
DO AppendFld WITH "FIELDTYPE", "C", 1
DO AppendFld WITH "VALUE_TYPE", "C", 1
DO AppendFld WITH "FILENAME", "C", 10
DO AppendFld WITH "ROW", "N", 5
DO AppendFld WITH "COL", "N", 2
DO AppendFld WITH "SYS_FLEN", "N", 2
DO AppendFld WITH "LENGTH", "N", 3
DO AppendFld WITH "DECIMALS", "N", 2
DO AppendFld WITH "TEMPLATE", "C", 80
DO AppendFld WITH "PICFUN", "C", 10
DO AppendFld WITH "PIC_CHOICE", "M", 10
DO AppendFld WITH "PIC_SCROLL", "N", 3
DO AppendFld WITH "DESCRIPT", "M", 10
DO AppendFld WITH "EXPRESSION", "M", 10
DO AppendFld WITH "L_BOUND", "M", 10
DO AppendFld WITH "U_BOUND", "M", 10
DO AppendFld WITH "DEF_VAL", "M", 10
DO AppendFld WITH "ED_COND", "M", 10
DO AppendFld WITH "OK_COND", "M", 10
DO AppendFld WITH "REJ_MSG", "C", 80
DO AppendFld WITH "HLP_MSG", "C", 80
DO AppendFld WITH "MEM_TYP", "N", 1
DO AppendFld WITH "EDITABLE", "N", 1
DO AppendFld WITH "CARRY", "L", 1
DO AppendFld WITH "DISPLAY", "N", 5
DO AppendFld WITH "STYLE", "N", 1
*-- Other interesting fields for future enhancements
DO AppendFld WITH "PRE_PROC", "M", 10
DO AppendFld WITH "POST_PROC", "M", 10
DO AppendFld WITH "HELP_PROC", "M", 10
DO AppendFld WITH "SELECT", "M", 10
DO AppendFld WITH "GROUPID", "N", 4
DO AppendFld WITH "CURRENTID", "N", 4
DO AppendFld WITH "NEXTID", "N", 4
DO AppendFld WITH "PREVID", "N", 4
DO AppendFld WITH "TLABEL", "N", 4
DO AppendFld WITH "PICKKEY", "C", 1
CREATE ( pc_DbfName ) FROM ( lc_tmp )
ERASE ( lc_tmp )
RETURN
*-- EOP: MakeStru
PROCEDURE AppendFld
PARAMETERS pc_name, pc_type, pn_len
*----------------------------------------------------------------------------
* NAME
* AppendFld - Adds a new field to a structure extended file
*
* PARAMETERS
* pc_name = name of the new field
* pc_type = type of the field
* pn_len = length of the field
*
*----------------------------------------------------------------------------
APPEND BLANK
REPLACE field_name WITH pc_name, ;
field_type WITH pc_type, ;
field_len WITH pn_len
RETURN
*-- EOP: AppendFld WITH pc_name, pc_type, pn_len
PROCEDURE FillDbf
*----------------------------------------------------------------------------
* NAME
* FillDbf - Fills the DBF with elements from the design surface
*
*----------------------------------------------------------------------------
*---------------------------------
*-- Start adding the form elements
*---------------------------------
{
return;
//-- eof: write_prg_header
enddef
define delimit_string( pC_String )
//---------------------------------------------------------------------
// DESCRIPTION
// Check the string for embedded string delimiters and use one
// that will not be a conflict.
//---------------------------------------------------------------------
var lC_LeftDelim,
lC_RightDelim,
lC_Result
;
if asc( pC_String ) < 32 then
if len( pC_String ) == 1 then
lC_Result = "CHR( " + asc( pC_String ) + " )"
else
if len( pC_String ) == 0 then
lC_Result = "''"
else
lC_Result = "REPLICATE( CHR( " + asc( pC_String ) + " ), " +
str( len( pC_String ) ) + " )"
endif
endif
else
//-- Assume single quotes are OK
lC_LeftDelim = "'"
lC_RightDelim = "'"
if at( "'", pC_String ) > 0 then
if at( "]", pC_String ) > 0 then
lC_LeftDelim = "\""
lC_RightDelim = "\""
else
lC_LeftDelim = "["
lC_RightDelim = "]"
endif
endif
lC_Result = lC_LeftDelim + pC_String + lC_RightDelim
endif
return lC_Result;
//-- eof:
enddef